<template>
  <h1>员工列表练习</h1>
  <input type="text" placeholder="请输入员工姓名" v-model="name">
  <input type="text" placeholder="请输入员工工资" v-model="salary">
  <input type="text" placeholder="请输入员工岗位" v-model="job">
  <button @click="add()">点我添加</button>
  <hr>
  <table border="1px">
    <tr>
      <th>员工编号</th>
      <th>员工姓名</th>
      <th>员工工资</th>
      <th>员工岗位</th>
    </tr>
    <tr v-for="(emp,i) in arr">
      <td>{{i+1}}</td>
      <td>{{emp.name}}</td>
      <td>{{emp.salary}}</td>
      <td>{{emp.job}}</td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";
const e=ref({name:'',salary:'',job:''});
const arr=ref([]);
const add=()=>{
  // 如果输入框有空值不允许新增
  if (e.value.name.trim()==''||e.value.salary.trim()==''||e.value.job.trim()=='')
    // 每准备一个员工数据，就存入到arr中
    arr.value.push(e.value);
}
// 新增成功后，清空输入框
e.value={name:'',salary:'',job:''};
// e.value={}
</script>

<style scoped>

</style>